<%@ page contentType="text/html;charset=UTF-8"%>
<%@include file="WEB-INF/views/include/taglib.jsp"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">


<script type="text/javascript"
	src="${ctx}/assets/js/lib/jquery/jquery-1.11.1.min.js"></script>

<title>幸运大抽奖</title>
</head>
<body>
<div>
	<input type="test" id="luckTotal" placeholder="输入中奖台数量"></input>
</div>
	<button id="stopAllBtn">一键全抽奖</button>
	<div id="listZone"></div>
	<div id="rsZone"></div>
	
	<button id="stopTaiBtn">抽台号</button>
	<div id="rsTaiZone"></div>
</body>
</html>

<script type="text/javascript">
	$(function() {
		var urls = {
			getData : "index/getTaiData",
			getLuck : "index/getAllLuck",
			getLuckTai : "index/getLuckTai"
		};
		
		$.post(urls.getData, function(rs) {
			var zone = $("#listZone");
			var html = "";
			$.each(rs, function(index, item) {
				html += "<div class='taiHao'>台号：" + item.taiHao;
				+"</div>";
				html += "<ul>"
				$.each(item.emps, function(index, item) {
					html += "<li>员工：" + item + "</li>";
				});
				html += "</ul>";
			});
// 			zone.append(html);
		});
		
		var stopAllBtn = $("#stopAllBtn").unbind().bind("click", function(){
			var luckTotal =$("#luckTotal").val();
			if(""==luckTotal){
				alert("输入中奖台数量");
				return ;
			}
			$.post(urls.getLuck,{"luckTotal":luckTotal}, function(rs) {
				var zone = $("#rsZone");
				var html = "";
				$.each(rs, function(index, item) {
					console.log(item);
					html += "<div class=''>幸运台号："+index+"。中奖员工：" + item +"</div>";
				});
				zone.empty().append(html);
			});
		});
		
		var taiCount = 0;
		var stopTaiBtn = $("#stopTaiBtn").unbind().bind("click", function(){
			var luckTotal =$("#luckTotal").val();
			$("#luckTotal").text("可抽台号次数"+taiCount);
			if(""==luckTotal){
				alert("输入中奖台数量");
				return ;
			}
			if(luckTotal==taiCount){
				alert("已没有台数抽奖次数");
				$("#luckTotal").attr("disabled","disabled");
				return ;
			}
			$.post(urls.getLuckTai, {"luckTotal":luckTotal}, function(rs) {
				taiCount ++;
				console.log(taiCount);
				var zone = $("#rsTaiZone");
				var html = "<div class=''>幸运台号："+rs.taiHao+"。</div>";
				$.each(rs.emps, function(index, item) {
					html += "<div class=''>有机会中奖员工：" + item +"</div>";
				});
				zone.empty().append(html);
			});
		});
		
		
		
		
	});
</script>
<style>
</style>